home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group01b.txt / 000133_icon-group-sender_Tue Aug 7 08:51:56 2001.msg < prev    next >
Internet Message Format  |  2002-01-03  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id f77FkWQ23106
  4.     for icon-group-addresses; Tue, 7 Aug 2001 08:46:32 -0700 (MST)
  5. Message-Id: <200108071546.f77FkWQ23106@baskerville.CS.Arizona.EDU>
  6. Date: Tue, 07 Aug 2001 13:07:16 +0200
  7. From: Anders Holtsberg <anders.holtsberg@decuma.com>
  8. X-Accept-Language: en
  9. To: icon-group@cs.arizona.edu
  10. Subject: Sorting
  11. Errors-To: icon-group-errors@cs.arizona.edu
  12. Status: RO
  13. Content-Length: 1011
  14.  
  15.  
  16. What is the simplest way to sort a list of records according to
  17. one of the fields? It seems hat this is not a one liner, or is 
  18. it? My quick hack is this:
  19.  
  20.  
  21. procedure sortbyfield(thelist, i)
  22.    t := table(&null)
  23.    every e := !thelist do t[e[i]] := e;
  24.    s := sort(t, 1)
  25.    w := []
  26.    every put(w, (!s)[2])
  27.    return w
  28. end
  29.  
  30.  
  31. For tables one can give a second argument to the sort procedure,
  32. but for lists the second argument is simply ignored. 
  33.  
  34. One simple for future enhancement to Icon is to use the above 
  35. semantics for a two argument call to sort, where the first 
  36. argument is either a list of records or a list of lists. Even 
  37. better is to also accept a string as second argument for the
  38. case that the first argument is a list of records. Is this
  39. sensible?
  40.  
  41.  
  42. Anders Holtsberg
  43.  
  44.  
  45. -- 
  46. _______________________________________________________________
  47.    Anders Holtsberg                  Decuma AB
  48.    tel +46 709 596305                Ideon V∩┐╜xthuset
  49.    anders.holtsberg@decuma.se        S-223 70 Lund, Sweden
  50.